<?php
/* SVN FILE: $Id: app_controller.php 4410 2007-02-02 13:31:21Z phpnut $ */
/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
 * Copyright 2005-2007, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2005-2007, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package			cake
 * @subpackage		cake.cake
 * @since			CakePHP(tm) v 0.2.9
 * @version			$Revision: 4410 $
 * @modifiedby		$LastChangedBy: phpnut $
 * @lastmodified	$Date: 2007-02-02 07:31:21 -0600 (Fri, 02 Feb 2007) $
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * This is a placeholder class.
 * Create the same file in app/app_controller.php
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package		cake
 * @subpackage	cake.cake
 */
#
class AppController extends Controller {

	var $components = array('Auth', 'Cookie', 'Session');
	var $cookieName = 'myCookie';
	var $cookieKey = 'has73js737hak2';
	var $cookieDomain; // info: use 127.0.0.1 in URI locally, otherwise cookie won't work

	function __construct() {
		parent::__construct();
		$this->cookieDomain = '.'.$_SERVER['SERVER_NAME'];
	}

	var $pathRoot = '/controller/index/';

	function beforeFilter() {
		Security::setHash("md5");
		global $sLang;
		$this->set('sLang', $sLang);
		$this->Auth->allow('display');
		$this->Auth->loginAction = '/controller/index/users/login';
		$this->Auth->loginRedirect = '/controller/index/home/';
		$this->Auth->logoutRedirect = '/controller/index/';
		$this->Auth->fields = array('username' => 'email', 'password' => 'password');
		$this->Auth->authorize = 'controller';
		$this->Auth->autoRedirect = false;
		$this->Auth->pathReferer = null;
		$this->authUser = ($oUser = $this->Auth->user())
			? $oUser['User']
			: null;
		$this->checkCookie();
	}

	function checkCookie(){
		if($this->authUser === null){
			if($oCookie = $this->Cookie->read('User')){
				$oUser = array('User' => array());
				$oUser['User']['email'] = $oCookie['email'];
				$oUser['User']['password'] = $oCookie['token'];
				$test = $this->Auth->login($oUser);
			}
		}
	}


	function isAuthorized() {

		// implement code that decides on a per request basis, if the logged
		// in user is allowed (authorized) to complete that request.
		// in this example, only users with an 'is_admin' field resolving to 'true'
		// will be granted access to admin routes
		if (isset($this->params['admin'])) {
//			return $this->Auth->user('is_admin');
		}
//		return false;
		return true;
	}

}

?>
